package ${packages.blockchain};

import ${packages.dto}.${classInfo.className}CreateRequest;
import ${packages.dto}.${classInfo.className}Response;
import ${basePackage}.common.BaseResponse;
import ${basePackage}.common.ResultUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * ${options.moduleDescription?default(classInfo.className + " 链上接口")}。
 */
@RestController
@RequestMapping("/${options.apiPrefix?default(moduleSimpleName)}/chain")
@RequiredArgsConstructor
@Validated
@ConditionalOnProperty(prefix = "feature.blockchain", name = "enabled", havingValue = "true", matchIfMissing = true)
@Tag(name = "${classInfo.className}链上接口", description = "调用区块链合约存证/查询")
public class ${classInfo.className}BlockchainController {

    private final ${classInfo.className}BlockchainFacade blockchainFacade;

    @PostMapping("/save")
    @Operation(summary = "链上存证示例", description = "根据业务需求补全参数和合约方法")
    public BaseResponse<String> save(@RequestBody @Valid ${classInfo.className}CreateRequest request) {
        return ResultUtils.success(blockchainFacade.saveToChain(request));
    }

    @GetMapping("/{id}")
    @Operation(summary = "链上查询示例", description = "根据业务需求补全参数和合约方法")
    public BaseResponse<${classInfo.className}Response> query(@PathVariable Long id) {
        return ResultUtils.success(blockchainFacade.queryFromChain(id));
    }
}
